package com.ithe.canteen.controller;

import com.ithe.canteen.common.Result;
import com.ithe.canteen.pojo.Order;
import com.ithe.canteen.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/queryOrder")
    public Result queryOrder(@RequestBody Order order) {
        String customerID = order.getOrderUser();
        return Result.success(orderService.queryOrder(customerID));
    }

    @PostMapping("/manager/queryOrder")
    public Result managerQueryOrder(@RequestBody Order order) {
        String dayQuery = order.getOrderDate();
        String stateQuery = order.getOrderState();
        return Result.success(orderService.managerQueryOrder(dayQuery, stateQuery));
    }

    @PostMapping("/addOrder")
    public Result addOrder(@RequestBody Order order) {
        String orderUser = order.getOrderUser();
        String orderDate = order.getOrderDate();
        String orderFood = order.getOrderFood();
        String orderState = order.getOrderState();
        return Result.success(orderService.addOrder(orderUser, orderDate, orderFood, orderState));
    }

    @PostMapping("/updateOrderState")
    public Result updateOrderState(@RequestBody Order order) {
        String orderState = order.getOrderState();
        String orderId = order.getOrderId();
        return Result.success(orderService.updateOrderState(orderState, orderId));
    }

    @PostMapping("/manager/updateState")
    public Result updateState(@RequestBody Order order) {
        String orderState = order.getOrderState();
        String orderId = order.getOrderId();
        return Result.success(orderService.updateOrderState(orderState, orderId));
    }

    @PostMapping("/deleteOrder")
    public Result deleteOrder(@RequestBody Order order) {
        String orderId = order.getOrderId();
        return Result.success(orderService.deleteOrder(orderId));
    }

    @PostMapping("/manager/deleteOrder")
    public Result managerDeleteOrder(@RequestBody Order order) {
        String orderId = order.getOrderId();
        return Result.success(orderService.deleteOrder(orderId));
    }
}
